package net.fdukedom.epicurus.plugin;

import net.fdukedom.epicurus.domain.entity.Plugin;
import net.fdukedom.epicurus.domain.entity.ExtensionPoint;

import java.util.Map;
import java.util.Set;

/**
 * @author Dmitry Y. Kochelaev
 */
public class ExtensionPointsLoader extends CollectionLoader<Plugin, ExtensionPoint> {
    public ExtensionPointsLoader(Plugin plugin) {
        super(plugin);
    }

    public ExtensionPoint parseAttributes(Map<String, String> attributes) {
        return new ExtensionPoint(attributes.get("name"), item);
    }

    public Set<ExtensionPoint> getLoadedCollection() {
        return item.getExtensionPoints();
    }

    public void disposeElement(ExtensionPoint element) {
        item.getExtensionPoints().remove(element);
        element.setPlugin(null);
    }

    public void addElement(ExtensionPoint element) {
        element.setPlugin(item);
        item.getExtensionPoints().add(element);
    }
}